<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        trayInfoId: {
          label: '托盘',
          type: 'list',
          placeholder: '请选择托盘',
          list: [],
          isNeedAdd: true,
          addNewItemFunc: this.addNewTray
        },
        trayOrderImage: {
          label: '入库单',
          type: 'uploadImage',
          imageType: 'uploadTrayImage'
        },
        trayOrderNo: {
          label: '托盘订单编号',
          placeholder: '托盘订单编号'
        },
        trayNumber: {
          label: '拖盘数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        trayPrice: {
          label: '纸箱价格',
          type: 'number',
          max: 1000,
          default: 0
        },
        factoryId: {
          label: '纸箱厂',
          type: 'list',
          placeholder: '请选择纸箱厂',
          list: []
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    addNewTray() {
      const cb = (newValue) => {
        this.initTrayList()
        this.dataForm.trayInfoId = newValue.id
      }
      this.$parent.openTrayInfoDialog(cb)
    },
    init(id) {
      this.dataForm.id = id || 0
      this.initTrayList()
      this.initFactoryIdList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('trayInfoId', 'trayOrderImage', 'trayOrderNo', 'trayNumber', 'trayPrice', 'factoryId', 'dayTime', 'status'),
        initApi: 'trayApi/trayAddInfo',
        saveApi: 'trayApi/saveTrayAdd',
        updateApi: 'trayApi/updateTrayAdd',
        objectName: 'trayAdd'
      })
    }
  }
}
</script>
